package org.apache.ibatis.demo;

import org.apache.ibatis.demo.entity.Blog;
import org.apache.ibatis.demo.mapper.BlogMapper;
import org.apache.ibatis.demo.mapper.BlogMapperInterface;
import org.apache.ibatis.demo.mapper2.BlogMapperPackage;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.HashMap;

/**
 * @fileName: TestDemo
 * @author: zengqf3
 * @date: 2021-3-9 11:47
 * @description:
 */
public class TestDemo2 {

  public static void main(String[] args) throws Exception {

    // 加载mybatis配置文件，并创建SqlSessionFactory实例
    String resource = "mybatis-config.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    //这个build方法可以接受几种不同的参数，如Reader/InputSteam等
    SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(inputStream);
    SqlSession sqlSession = factory.openSession();

    BlogMapper mapper = sqlSession.getMapper(BlogMapper.class);
    //class com.sun.proxy.$Proxy5
//    System.out.println(mapper.getClass());
    //org.apache.ibatis.binding.MapperProxy@2752f6e2
//    System.out.println(mapper);
//    Blog blog = new Blog();
//    blog.setId(101);
//    blog.setName("feige");
//    blog.setTitle("gaosu");
//    int update = mapper.update(blog);
//    System.out.println(update);

    Blog blog1 = mapper.selectBlogById(1L);
    System.out.println(blog1);


//    Blog blog2 = new Blog();
//    blog2.setId(102);
//    blog2.setName("feige");
//    blog2.setTitle("gaosu");
////    int insert = mapper.insert(blog2);
////    System.out.println(insert);
//    //默认不自动提交事务，需要手动提交事务
//    sqlSession.commit();
//    HashMap
  }

}
